<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增标签')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-lable-add">
			<div class="form-group">
				<label class="col-sm-3 control-label"><span style="color: red; ">*</span>标签ID：</label>
				<div class="col-sm-8">
					<input id="tagId" name="tagId" class="form-control" type="text" oninput="showType()">
				</div>
			</div>
<!--			<div class="form-group">-->
<!--				<label class="col-sm-3 control-label">标签类型：</label>-->
<!--				<div class="col-sm-8">-->
<!--					<input id="modelType" name="modelType" class="form-control" type="text" readonly="true">-->
<!--				</div>-->
<!--			</div>-->
<!--			<input id="tagType" name="tagType" class="form-control" type="hidden">-->
<!--			<div class="form-group">-->
<!--				<label class="col-sm-3 control-label">标签型号：</label>-->
<!--				<div class="col-sm-8">-->
<!--					<input id="modelNumber" name="modelNumber" class="form-control" type="text" readonly="true">-->
<!--				</div>-->
<!--			</div>-->
			<div class="form-group">
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input id="remark" name="remark" class="form-control" type="text">
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		// 去掉所有input的autocomplete, 显示指定的除外 
		$(function(){
			$('input:not([autocomplete]),textarea:not([autocomplete]),select:not([autocomplete])').attr('autocomplete', 'off');
		});
		var prefix = ctx + "system/lable"
		$("#form-lable-add").validate({
			rules:{
				tagId:{
					required:true,
					rangelength:[10,12],
					remote: {
						url: prefix + "/checkLableIdUnique",
						type: "post",
						dataType: "json",
						data: {
							name : function() {
								return $.common.trim($("#tagId").val());
							}
						},
						dataFilter: function(data, type) {
							return $.validate.unique(data);
						}
					}
				},

			},
			messages: {

				"tagId": {
					rangelength:"请输入12位长度标签Id",
					remote: "标签Id已经存在"
				},
			},
			focusCleanup: true
		});

		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/add", $('#form-lable-add').serialize());
	        }
	    }
		function showType(){
			var tagId = $('#tagId').val();
			if (tagId.length>9){
				var code = tagId.substring(8,10);
				$.ajax({
					url:"/system/deviceModel/getDeviceModelByCode?modelCode="+code,
					type: 'post',
					data: "",
					cache: false,
					dataType:"json",
					async:false,
					// contentType: false,
					// processData: false,
					success: function (result) {
						var data = result.data;
						if (data != null&&data!=""){
							$('#tagType').val(data.modelId);
							$('#modelNumber').val(data.modelNumber);
							$('#modelType').val(data.modelType);
						}else {
							$('#modelNumber').val("");
							$('#modelType').val("");
							$('#tagType').val("");
						}
					}
				});
			}else {
				$('#tagType').val("");
				$('#modelNumber').val("");
				$('#modelType').val("");
			}
		}
	</script>
</body>
</html>
